package red.uec.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class RestfulResponse implements Serializable {
    private static final long serialVersionUID = -3178145987778863842L;

    /**
     * 返回码
     */
    private Integer code;
    /**
     * 返回消息
     */
    private String message;

    public <T extends RestfulResponse> T success(){
        this.code = 1;
        this.message = "操作成功！";
        return (T)this;
    }

    public <T extends RestfulResponse> T success(String message){
        this.code = 1;
        this.message = message;
        return (T)this;
    }

    public <T extends RestfulResponse> T unknown(){
        this.code = 0;
        this.message = "系统繁忙，请稍候再试！！";
        return (T)this;
    }

    public <T extends RestfulResponse> T fail(){
        this.code = -1;
        this.message = "操作失败！";
        return (T)this;
    }

    public <T extends RestfulResponse> T fail(String message){
        this.code = -1;
        this.message = message;
        return (T)this;
    }
}
